package com.norns.torque.entrty

import androidx.room.TypeConverter
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId


class DateTypeConverter {

    @TypeConverter
    fun toDate(timestamp: Long): LocalDateTime {
        //秒级时间戳转LocalDateTime
        val zoneId = ZoneId.systemDefault()
        val localDateTime =
            Instant.ofEpochSecond(timestamp).atZone(zoneId).toLocalDateTime()

        val localDateTimeLongTime = LocalDateTime.ofInstant(
            Instant.ofEpochMilli(timestamp),
            ZoneId.systemDefault()
        )
        return localDateTime
    }
    @TypeConverter
    fun toTimestamp(localDateTime: LocalDateTime): Long {
        return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond()
    }
}